Page({
  data: {
    dialogVisible: false,
    statusMsg: {
      1: '审核中',
      2: '审核通过',
      3: '审核失败',
    },
    statusType: {
      1: 'info',
      2: 'success',
      3: 'fail',
    }
  },
  onShow() {
    this.getHouseList()
  },
  async getHouseList() {
    const res = await wx.http.get('/room')
    // console.log(res.data);
    this.setData({
      roomList: res.data
    })
  },
  swipeClose(ev) {
    console.log(ev);
    const id = ev.mark.id
    this.setData({
      id: id
    })
    const {
      position,
      instance
    } = ev.detail

    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })

      // swiper-cell 滑块关闭
      instance.close()
    }
  },

  goDetail(e) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + e.mark.id,
    })
  },
  //增加房屋
  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
  //删除房屋
  async deleteHouse(id) {
    await wx.http.delete(`/room/${id}`)
  },
  async dialogClose(e) {
    console.log(e);
    if (e.detail === 'confirm') {
      await this.deleteHouse(this.data.id)
      this.getHouseList()
    }
  }
})